/**
 * 
 */
package com.org.javabody.forApi.fromsmalltobig;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Administrator
 *
 */
public class ForSpendTimeDemo {
	private final static Logger log = LoggerFactory.getLogger(ForSpendTimeDemo.class); 
	
	public void spendTime(int num1, int num2) {
		Long a = System.nanoTime();  
		for (int i=0; i<num1; i++ ) {
			for(int j=0; j<num2; j++) {
				
			}
		}
		Long b = System.nanoTime(); 
		log.info((b-a)+"");
	}
	
	
	public void calculateTime() {//使用位操作进行计算

		int num1=0;
		int num2=0;
		Long a = System.nanoTime();  
		for (int i=0; i<10000; i++ ) {
			num1 += i << 3;
			num2 += i >> 1;
		}
		Long b = System.nanoTime(); 
		log.info(num1+","+num2+","+(b-a));
	}
	
	public void calculateTime2() {
		int num1=0;
		int num2=0;
		Long a = System.nanoTime();  
		for (int i=0; i<10000; i++ ) {
			num1 += i*8;
			num2 += i/2;
		}
		Long b = System.nanoTime(); 
		log.info(num1+","+num2+","+(b-a));
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub


         new ForSpendTimeDemo().spendTime(10000, 100000);//双循环从小到大耗时比从大到小耗时要少

         new ForSpendTimeDemo().spendTime(100000, 10000);
         new ForSpendTimeDemo().calculateTime();
         new ForSpendTimeDemo().calculateTime2();
	}

}